import { ApiCall } from "tsrpc";
import { ReqAddData, ResAddData } from "../shared/protocols/PtlAddData";
import { Global } from "../models/Global";

// This is a demo code file
// Feel free to delete it

export default async function (call: ApiCall<ReqAddData, ResAddData>) {
    // Error
    // if (call.req.content === '') {
    //     call.error('Content is empty');
    //     return;
    // }

    let time = new Date();

    const ret = await Global.db.collection('Asset').insertOne({
        RukuDate: call.req.RukuDate,
        AssetNum: call.req.AssetNum,
        SerialNum: call.req.SerialNum,
        EquipmentName: call.req.EquipmentName,
        EquipmentModel: call.req.EquipmentModel,
        Flag: call.req.Flag,
        Custodian: call.req.Custodian,
        DepartmentHead: call.req.DepartmentHead,
        User: call.req.User,
        AbnormalInfo: call.req.AbnormalInfo,
        time: time});
    return call.succ({ insertedId: ret.insertedId.toString() })


    // Success
    call.succ({
        insertedId: ret.insertedId.toString()
    });
}